from gluon.storage import Storage
settings = Storage()

settings.migrate = True
settings.title = 'forms2pdf'
settings.subtitle = 'We make pdf forms for you'
settings.author = 'Massimo Di Pierro'
settings.author_email = 'mdipierro@cs.depaul.edu'
settings.keywords = ''
settings.description = ''
settings.database_uri = 'sqlite://storage.sqlite'
settings.security_key = '3dd19cd8-4379-42c5-bd9e-6511836e5033'
settings.email_server = 'localhost'
settings.email_sender = 'you@example.com'
settings.email_login = ''
settings.login_method = 'local'
settings.login_config = ''
settings.layout_theme = 'Pluralism'


### we prepend t_ to tablenames and f_ to fieldnames for disambiguity
import uuid

crud.settings.formstyle="table2cols"

########################################
db.define_table('t_form',
    Field('id','id',
          represent=lambda id:SPAN(id,' ',A('view',_href=URL('form_read',args=id)))),
    Field('f_name', type='string',
          label=T('Name')),
    Field('f_content', type='text',
          represent=lambda x: MARKMIN(x),
          comment='WIKI (markmin)',
          label=T('Content')),
    Field('f_public', type='boolean', default=False,
          label=T('Available to all users?')),
    Field('f_uuid',default=str(uuid.uuid4()),
          writable=False,readable=False),
    Field('f_created_on','datetime',default=request.now,
          label=T('Created On'),writable=False,readable=False),
    Field('f_modified_on','datetime',default=request.now,
          label=T('Modified On'),writable=False,readable=False,
          update=request.now),
    Field('f_created_by',db.auth_user,default=auth.user_id,
          label=T('Created By'),writable=False,readable=False),
    Field('f_modified_by',db.auth_user,default=auth.user_id,
          label=T('Modified By'),writable=False,readable=False,
          update=auth.user_id),
    format='%(f_name)s',
    migrate=settings.migrate)

db.t_form.f_name.default="Example: Job Application"
db.t_form.f_content.default="""
# Job Application
## Instuructions
- please complete the form
- export it in PDF
- print it
- sign it
- fax it to 111-111-1111
## Job Application Questionaire
### Personal data
--------
**first name:** | ``first_name``:input_text
**last name:** | ``last_name``:input_text
**email:** | ``email``:input_text
--------
### Skills
``skills``:input_area
### Signature
``accept``:input_bool Accept [[Confidentiality Agreement http://example.com]]

Signature: ..................................... Date: ``today``:input_date 
"""






# initialization.py
# created from plugin_plugin/template_plugin_initialization_py
# copyright christopher steel, 2011, on behalf of Voice of Access
import os
cwd = os.getcwd()
current_app = os.path.join(cwd,'applications',request.application)
#initialization_file_path = os.path.join(current_app,'models','plugin_pdf_form2pdf','000_uc_initialization.py')
initialization_file_path = os.path.join(current_app,'models','000_uc_initialization.py')

# create an initialization file if we do not have one
if not 'initialization_file_created' in globals():
    if not os.path.exists(initialization_file_path):
        our_file = open(initialization_file_path,"w")
        our_text = '# file created by plugin_pdf_form2pdf\n'
        our_text += 'initialization_file_created = True\n'
        our_file.writelines(our_text)
        our_file.close()
else:
    print('models/plugin_pdf_form2pdf/initialization.py found')
    print('initialization_file_created globals')


if not 'group_plugin_pdf_form2pdf_admin_created' in globals():
    if not db(db.auth_group.role=='plugin_pdf_form2pdf_admin').select(): 
        db.auth_group.insert(role='plugin_pdf_form2pdf_admin',description='user to administer plugin_pdf_form2pdf')
        our_file = open(initialization_file_path,"a")
        our_text = '# entry created by plugin_pdf_form2pdf\n'
        our_text += 'group_plugin_pdf_form2pdf_admin_created = True\n'
        our_file.write(our_text)
        our_file.close()
else:
    print('models/plugin_pdf_form2pdf/initialization.py found')
    print('group_plugin_pdf_form2pdf_admin_created globals')


response.menu+= [
    (T('plugin_pdf_form2pdf'), False, URL('plugin_pdf_form2pdf','index'),
        [
            (T('plugin_pdf_form2pdf actions'), False, URL('plugin_pdf_form2pdf','index'),
                [
                    (T('form create'), False, URL('plugin_pdf_form2pdf', 'form_create')),
                    (T('form search'), False, URL('plugin_pdf_form2pdf', 'form_search')),
                ]),
            (T('about'), False, URL(request.application,'plugin_pdf_form2pdf','display_static',args='about')),
            (T('license'), False, URL(request.application,'plugin_pdf_form2pdf','display_static',args='license')),
        ]
   )]
